package org.project.service.mq;

import java.util.Properties;

import javax.jms.Destination;
 

import javax.jms.JMSException;
import javax.jms.Message;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessagePostProcessor;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

@Service
public class JMSSender {
	 
	private JmsTemplate jmsTemplate;
 
	private Properties msgheader;
 
	private Destination replyTo;
 
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}
 
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
 
	/**
	 * @return Returns the msgheader.
	 */
	public Properties getMsgheader() {
		return msgheader;
	}
 
	/**
	 * @param msgheader The msgheader to set.
	 */
	public void setMsgheader(Properties msgheader) {
		this.msgheader = msgheader;
	}
 
	/**
	 * @return Returns the replyTo.
	 */
	public Destination getReplyTo() {
		return replyTo;
	}
 
	/**
	 * @param replyTo The replyTo to set.
	 */
	public void setReplyTo(Destination replyTo) {
		this.replyTo = replyTo;
	}
 
	public void sendMesage(Object object) {
		JSONObject json = new JSONObject();
		json.put("orderData", object);
		jmsTemplate.convertAndSend(replyTo, json.toJSONString(),new MessagePostProcessor() {
			
			public Message postProcessMessage(Message message) throws JMSException {
				message.setStringProperty("aa", "dd");
				return message;
			}
		});
	}
}
 